package cn.falconnect.adserver.adapter.persistence.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import cn.falconnect.adserver.adapter.persistence.typehandler.ConnectionEnumTypeHandler;
import cn.falconnect.adserver.adapter.persistence.typehandler.OSEnumTypeHandler;
import cn.falconnect.adserver.adapter.persistence.typehandler.OperatorEnumTypeHandler;
import cn.falconnect.adserver.domain.ad.StrategyDeviceMap;

@Component
public interface StrategyDeviceMapDao {

	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "strategy_id", property = "strategyId"),
			@Result(column = "connect_type", property = "connectType"),
			@Result(column = "connect_type", property = "connectTypeList",typeHandler=ConnectionEnumTypeHandler.class),
			@Result(column = "os", property = "os"),
			@Result(column = "os", property = "osList",typeHandler=OSEnumTypeHandler.class),
			@Result(column = "operator", property = "operator"),
			@Result(column = "operator", property = "operatorList",typeHandler=OperatorEnumTypeHandler.class),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime")})
	@Select("select * from strategy_device_map ")
	List<StrategyDeviceMap> findAll();

	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "strategy_id", property = "strategyId"),
			@Result(column = "connect_type", property = "connectType"),
			@Result(column = "connect_type", property = "connectTypeList",typeHandler=ConnectionEnumTypeHandler.class),
			@Result(column = "os", property = "os"),
			@Result(column = "os", property = "osList",typeHandler=OSEnumTypeHandler.class),
			@Result(column = "operator", property = "operator"),
			@Result(column = "operator", property = "operatorList",typeHandler=OperatorEnumTypeHandler.class),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime")})
	@Select("select * from strategy_device_map where update_time >= #{value} ")
	List<StrategyDeviceMap> findAfterTime(String warmUpTime);
	
	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "strategy_id", property = "strategyId"),
			@Result(column = "connect_type", property = "connectType"),
			@Result(column = "connect_type", property = "connectTypeList",typeHandler=ConnectionEnumTypeHandler.class),
			@Result(column = "os", property = "os"),
			@Result(column = "os", property = "osList",typeHandler=OSEnumTypeHandler.class),
			@Result(column = "operator", property = "operator"),
			@Result(column = "operator", property = "operatorList",typeHandler=OperatorEnumTypeHandler.class),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime")})
	@Select("select * from strategy_device_map where strategy_id = #{id} and status = #{status}")
	StrategyDeviceMap selectByStrategyId(@Param("id") long id, @Param("status") int status);

}
